<%@ page import="News.service.UserServer" %>
<%@ page import="java.util.List" %>
<%@ page import="News.entity.News" %>
<%@ page import="javax.swing.*" %>
<%@ page import="News.service.NewsServer" %>
<%@ page import="java.util.Map" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/29 0029
  Time: 16:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>cUser</title>
</head>
<body>
管理员页面
<%--<table style="border: 1px solid red">--%>
<%--    <tr>--%>
<%--        <td>新闻id</td>--%>
<%--        <td>新闻内容</td>--%>
<%--        <td>删除id</td>--%>
<%--    </tr>--%>
<%--    <%--%>
<%--        UserServer login=new UserServer();--%>
<%--        List<News> list = login.show();--%>
<%--        int i=0;--%>
<%--        for(News news:list){--%>
<%--            i++;--%>
<%--    %>--%>
<%--        <tr>--%>
<%--            <td><%=i%></td>--%>
<%--            <td><%=news.getNewInfo()%></td>--%>
<%--            <td><%=news.getNewId()%></td>--%>
<%--        </tr>--%>
<%--    <%--%>
<%--        }--%>
<%--    %>--%>
<%--</table>--%>

<form action="cUser.jsp" method="post" id="newsForm">
    <%
        request.setCharacterEncoding("UTF-8");
        String pageSizeInput=request.getParameter("pageSizeInput");
        String pageNoInput=request.getParameter("pageNoInput");

        NewsServer newsController = new NewsServer();
        Map<String, Object> newsMap = newsController.queryNews(pageSizeInput, pageNoInput);
        List<Map<String, Object>> newsList = (List<Map<String, Object>>) newsMap.get("list");
        out.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+"ID" + "&emsp;");
        out.println("新闻" + "&emsp;");
        out.println("发布之间" + "&emsp;<br>");
        out.println("<ul>");
        if(newsList!=null){
            for (Map<String, Object> item : newsList) {
                out.println("<li style='list-style-type:none;' name=" + item.get("text") + " id=" + item.get("id") + ">");
                out.println(item.get("id") + "&emsp;");
                out.println(item.get("text") + "&emsp;");
                out.println(item.get("createtime") + "&emsp;");
                out.println("</li>");
            }
        }
        out.println("<input type='hidden' id='pageSize' name='pageSizeInput' value='"+newsMap.get("PageSize")+"'/>");
        out.println("<input type='hidden' id='pageNo' name='pageNoInput' value='"+newsMap.get("PageNo")+"'/>");
        out.println("<input type='button' value='上一页' onclick='pageFn("+newsMap.get("prevPage")+","+newsMap.get("PageSize")+")'/>");
        out.println("<input type='button' value='下一页' onclick='pageFn("+newsMap.get("nextPage")+","+newsMap.get("PageSize")+")'/>");
        out.println("<br/>"+"上一页："+newsMap.get("prevPage")+"<br/>");
        out.println("当前页："+newsMap.get("PageNo")+"<br/>");
        out.println("下一页："+newsMap.get("nextPage")+"<br/>");
        out.println("总页数："+newsMap.get("total")+"<br/>");
        out.println("每页数："+newsMap.get("totalPage")+"<br/>");
    %>
</form>

<script>
    function pageFn(nextPage, nextSize){
        let newsNode = document.getElementById("newsForm");
        document.getElementById("pageSize").value = nextSize;
        document.getElementById("pageNo").value = nextPage;
        newsNode.submit();
    }
</script>

<form action="addNewsControl.jsp" method="post">
<input type="text" name="news" placeholder="添加新闻的内容">
<input type="submit" value="添加新闻"/>
</form><br/>

<form action="dropNewsControl.jsp" method="post">
<input type="text" name="news" placeholder="删除新闻的删除id">
<input type="submit" value="删除新闻"><br/>
</form>

<form action="Exit.jsp" method="post">
<input type="submit" value="登出">
</form>

<form action="doupload.jsp" enctype="multipart/form-data" method="post">
    <p>选择图片</p><input type="file" name="nfile"/>
    <input type="submit" value="提交"/>
</form>


</body>
</html>
